import Vue from 'vue'
import store from './store'
import App from './App'
import cuCustom from './components/head/cu-custom.vue'
import cuBar from './components/bar/index.vue'
import uView from 'uni_modules/uview-ui'
import Router from '@/common/router/uni_router'
import { mapMutations } from 'vuex'
Vue.use(Router)
const router = new Router()
Vue.component('cu-custom', cuCustom)
import ComFunJS from '@/common/comfun/ComFun'
Vue.prototype.$ComFunJS = ComFunJS
Vue.use(uView)
Vue.component('cu-bar', cuBar)
router.beforeEach(function(to, from, next) {
  let norouter = []
  uni.getStorage({
    key: 'token',
    complete: function(res) {
      if (!res.data && to.page != '/pages/public/login' && norouter.indexOf(from.page) == -1) {
        // 测试小程序跳转
        next({ page: '/pages/public/login', params: {}, method: 'reLaunch' })
      } else {
        next()
      }
    },
  })
})



const msg = (title, duration = 1500, mask = false, icon = 'none') => {
  //统一提示方便全局修改
  if (Boolean(title) === false) {
    return
  }
  uni.showToast({
    title,
    duration,
    mask,
    icon
  })
}
const prePage = () => {
  let pages = getCurrentPages()
  let prePage = pages[pages.length - 2]
  // #ifdef H5
  return prePage
  // #endif
  return prePage.$vm
}
Vue.config.productionTip = false
Vue.prototype.$fire = new Vue()
Vue.prototype.$store = store
Vue.prototype.$api = { msg, prePage }

App.mpType = 'app'

const app = new Vue({ ...App })
app.$mount()